package my.jieh.tips.util.string;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Blueimp</p>
 * @author jieh
 * @version 1.0
 */

public class DemoInterfaceMain {
  static void show(DemoInterfaceProcess process, int t){
    long startTime = System.currentTimeMillis();
    long startMem = Runtime.getRuntime().freeMemory();

    process.process(t);

    long endMem = Runtime.getRuntime().freeMemory();
    long endTime = System.currentTimeMillis();

    System.out.println("Use memory: " + (startMem - endMem));
    System.out.println("Use Time: " + (endTime - startTime));
  }

  public static void main(String[] args) {

    DemoInterfaceProcess bed = new DemoInterfaceProcess(){
      public void process(int t){
        String str = "";
        for(int i=0; i<t; i++){
          str += "a";
        }
      }
    };

    DemoInterfaceProcess good = new DemoInterfaceProcess(){
      public void process(int t){
        StringBuffer sb = new StringBuffer();
        for(int i=0; i<t; i++){
          sb.append("a");
        }
      }
    };

    int t = 10000;
    System.out.println("==========================================");
    System.out.println("Bed Test Time : " + t);
    show(bed, t);
    show(good, t);

    t = 20000;
    System.out.println("==========================================");
    System.out.println("Bed Test Time : " + t);
    show(bed, t);
    show(good, t);
  }
}